<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/jquery.raty.js"></script>
<link type="text/css" rel="stylesheet" href="css/application.css">
<link rel="stylesheet" href="css/layui.css" />
<script src="js/layui.js"></script>
<style type="text/css">
.layui-form-label{padding-left:0px;text-algin:right;width:120px;}
.layui-input-block{margin-left:140px;}
</style>
</head>
<body style="padding:5px;background:white;">
<div style="width:100%;margin:0 auto;text-align:center;">
	<img id="in" src="" width=150 height=200/><br>
	<label id="inname" style="font-size:18px;color:red;margin:5px;">名字</label>
</div>
<form style="margin:15px;">
<div class="layui-form-item layui-form-text">
  <label class="layui-form-label"><span style="font-size:18px;">请键入</span><br>你的评价</label>
  <div class="layui-input-block">
    <textarea placeholder="请输入内容" id="context" class="layui-textarea"></textarea>
  </div>
</div>
<div class="layui-form-item layui-form-text">
  <label class="layui-form-label">给本次服务<br><span style="font-size:18px;">打个分吧</span></label>
  <div class="layui-input-block">
    <div class="demo" style="height:58px;line-height:58px;"><div id="click-demo"></div></div>
  </div>
</div>
<div class="layui-form-item">
  <div class="layui-input-block">
    <button class="layui-btn" id="subbtn" type="button" lay-filter="demo1">立即提交</button>
    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  </div>
</div>
</form>
<script type="text/javascript">
layui.use(['layer','laydate','form'],function(){
	var layer = layui.layer;  //layer初始化
	
	$.post("querySingle",{'inid':queryString("inid")},function(data){
		if(data.code=="0"){
			$("#in").attr("src",data.data[0].inimg);
			$("#inname").text(data.data[0].inname);
		}
	})
	$.fn.raty.defaults.path = 'image/';
	var fen="";
	$('#click-demo').raty({
	    click: function(score, evt) {
	        // layer.alert('ID: ' + $(this).attr('id') + "\nscore: " + score + "\nevent: " + evt.type)
	        fen = score;
	    }
	});
	$("#subbtn").click(function(){
		if($("#context").val()=="" || fen==""){
			layer.alert("必须全部输入哦");
			return false;
		}
		$.post("insmsg",{'evtext':$("#context").val(),'evgr':fen,'wid':queryString("wid")},function(data){
			//当在iframe页面关闭自身时，在iframe页执行以下js脚本
			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			if(data!=null){
				if(data.evgr=="5" || data.evgr=="4"){
					layer.confirm("评价成功！感谢您的赞赏！",function(index){
						parent.layer.closeAll();
						parent.location.href="personal";
					})
				}else if(data.evgr=="3"){
					layer.confirm("评价成功！您的评价将成为我们前进鞭策的动力！",function(index){
						parent.layer.closeAll();
						parent.location.href="personal";
					});
				}else{
					layer.confirm("评价成功！我们非常抱歉给您这次不好的体验，我们将会更加努力！",function(index){
						parent.layer.closeAll();
						parent.location.href="personal";
					});
				}
			}else{
				layer.confirm("评价失败了，请稍后再试！",function(index){
					parent.layer.closeAll();
					parent.location.href="personal";
				});
			}
			
		})
	})
	
	

	// 切割地址栏的参数
	function queryString(name) {
	    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	    var regexS = "[\\?&]" + name + "=([^&#]*)";
	    var regex = new RegExp(regexS);
	    var results = regex.exec(window.location.search);
	    if(results == null) {
	        return "";
	    }
	    else {
	        return decodeURIComponent(results[1].replace(/\+/g, " "));
	    }
	}
	
	
})


</script>
</body>
</html>